package com.example.jwtdemo.config;

import com.example.jwtdemo.interceptors.JWTInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author HMQ
 * @date 2020/9/20 15:22
 */

@Configuration
public class InterceptorConfig implements WebMvcConfigurer {

    /**
     * 注册JwtInterceptor拦截器
     * @param registry 注册机
     */
    @Override
    public void addInterceptors(InterceptorRegistry registry){
        registry.addInterceptor(new JWTInterceptor())
                //其它接口都要token验证
                .addPathPatterns("/user/test")
                //用户登录请求除外
                .excludePathPatterns("/user/login");
    }
}
